#include "SoundManager.h"
#include <assert.h>
#undef PlaySound // undefines a predefined '#define PlaySound', already in the libary. (include in .cpp and .h)

SoundManager::SoundManager()
{
	int audio_rate = 22050;
	Uint16 audio_format = AUDIO_S16SYS;
	int audio_channels = 2;
	int audio_buffers = 2048;

	if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, audio_buffers) != 0)
	{
	}
}

bool SoundManager::PlaySound (const std::string& Tag)
{
	int channel = Mix_PlayChannel (-1, SoundMap[Tag], 0);
	return true;
}


void SoundManager::LoadSound(const std::string& FilePath, const std::string& Tag)
{
	Mix_Chunk* m_Sound = Mix_LoadWAV (FilePath.c_str());
	assert(m_Sound);

	SoundMap[Tag] = m_Sound;
}
void SoundManager::LoadMusic(const std::string& FilePath, const std::string& Tag)
{

	Mix_Music* music = 0;

	music = Mix_LoadMUS(FilePath.c_str());
	assert(music);

	MusicMap[Tag] = music;

}


bool SoundManager::PlayMusic(const std::string& Tag, const int Loops)
{
	Mix_PlayMusic(MusicMap[Tag], Loops);
	return true;
}

void SoundManager::FadeIn()
{
	Mix_FadeInChannel(-1, m_Sound, 0, 1000);
}

void SoundManager::FadeOut()
{
	Mix_FadeOutChannel(-1, 1000);
}